package com.usian.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.behavior.service.ApFollowBehaviorService;
import com.usian.model.article.pojos.ApArticleConfig;
import com.usian.model.behavior.dtos.FollowBehaviorDto;
import com.usian.model.behavior.pojos.ApFollowBehavior;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


import java.util.Optional;

@Component
public class ApFollowBehaviorListener {

    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = "follow_topic")
    public void receiveMessage(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            String value = (String) record.value();
            FollowBehaviorDto followBehaviorDto = JSON.parseObject(value, FollowBehaviorDto.class);
            apFollowBehaviorService.saveFollowBehavior(followBehaviorDto);
        }
    }

}
